﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using SME.Food.Surperise.DBHelper;

namespace SME.Food.Surperise.DAL
{
    /// <summary>
    /// 数据访问类:Bas_Enter_User_Model
    /// </summary>
    public partial class Bas_Enter_User_Model
    {
        public Bas_Enter_User_Model()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Bas_Enter_User");
            strSql.Append(" where ID=" + ID);
            return DbHelper.Exists(strSql.ToString());
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(SME.Food.Surperise.Model.Bas_Enter_User_Model model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Bas_Enter_User(");
            strSql.Append("Login_Name,Password,Enter_No,Enter_Name,Enter_ShortName,Link_Man,Sex,Link_Phone,Email," +
                          "qqNum,Ent_Address,Ent_Logo,Ent_ShowPic,Ent_Commitment,Ent_Introduce,Ent_Lat,Ent_Lnt," +
                          "Ent_Isparagon,District_Id,FDAID,Kitchen_View,EnterType,LicenceType,LicenceNum," +
                          "LicenceStartDate,LicenceEndDate,LastQuantizationLevel,TheQuantizationLevel," +
                          "ApprovalProject,RegisteredOwner)");
            strSql.Append(" values (");
            strSql.Append( string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19}," +
                          "{20},{21},{22},{23},{24},{25},{26},{27},{28},{29}"
                          ,model.Login_Name,model.Password,model.Enter_No,model.Enter_Name,model.Enter_ShortName,
                          model.Link_Man,model.Sex,model.Link_Phone,model.Email,model.qqNum,model.Ent_Address,
                         model.Ent_Logo,model.Ent_ShowPic,model.Ent_Commitment,model.Ent_Introduce,model.Ent_Lat,
                          model.Ent_Lnt,model.Ent_Isparagon,model.District_Id,model.FDAID,model.Kitchen_View,
                          model.EnterType,model.LicenceType,model.LicenceNum,model.LicenceStartDate,model.LicenceEndDate,
                          model.LastQuantizationLevel,model.TheQuantizationLevel,model.ApprovalProject,model.RegisteredOwner));
            object obj = DbHelper.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SME.Food.Surperise.Model.Bas_Enter_User_Model model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Bas_Enter_User set ");
            strSql.Append("Login_Name='"+model.Login_Name+"',");
            strSql.Append("Password='"+model.Password+"',");
            strSql.Append("Enter_No='"+model.Enter_No+"',");
            strSql.Append("Enter_Name='"+model.Enter_Name+"',");
            strSql.Append("Enter_ShortName='"+model.Enter_ShortName+"',");
            strSql.Append("Link_Man='"+model.Link_Man+"',");
            strSql.Append("Sex="+model.Sex+",");
            strSql.Append("Link_Phone='"+model.Link_Phone+"',");
            strSql.Append("Email='"+model.Email+"',");
            strSql.Append("qqNum='"+model.qqNum+"',");
            strSql.Append("Ent_Address='"+model.Ent_Address+"',");
            strSql.Append("Ent_Logo='"+model.Ent_Logo+"',");
            strSql.Append("Ent_ShowPic='"+model.Ent_ShowPic+"',");
            strSql.Append("Ent_Commitment='"+model.Ent_Commitment+"',");
            strSql.Append("Ent_Introduce='"+model.Ent_Introduce+"',");
            strSql.Append("Ent_Lat='"+model.Ent_Lat+"',");
            strSql.Append("Ent_Lnt='"+model.Ent_Lnt+"',");
            strSql.Append("Ent_Isparagon='"+model.Ent_Isparagon+"',");
            strSql.Append("District_Id="+model.District_Id+",");
            strSql.Append("FDAID="+model.FDAID+",");
            strSql.Append("Kitchen_View="+model.Kitchen_View+",");
            strSql.Append("EnterType="+model.EnterType+",");
            strSql.Append("LicenceType="+model.LicenceType+",");
            strSql.Append("LicenceNum='"+model.LicenceNum+"',");
            strSql.Append("LicenceStartDate='"+model.LicenceStartDate+"',");
            strSql.Append("LicenceEndDate='"+model.LicenceEndDate+"',");
            strSql.Append("LastQuantizationLevel='"+model.LastQuantizationLevel + "',");
            strSql.Append("TheQuantizationLevel='"+model.TheQuantizationLevel+"',");
            strSql.Append("ApprovalProject='"+model.ApprovalProject+"',");
            strSql.Append("RegisteredOwner='" + model.RegisteredOwner + "'");
            strSql.Append(" where ID="+model.ID);
            int rows = DbHelper.ExcuteNoQuery(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Bas_Enter_User ");
            strSql.Append(" where ID="+ID);
            int rows = DbHelper.ExcuteNoQuery(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Bas_Enter_User ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = DbHelper.ExcuteNoQuery(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SME.Food.Surperise.Model.Bas_Enter_User_Model GetModel(int ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,Login_Name,Password,Enter_No,Enter_Name,Enter_ShortName,Link_Man,Sex,Link_Phone,Email,qqNum,Ent_Address,Ent_Logo,Ent_ShowPic,Ent_Commitment,Ent_Introduce,Ent_Lat,Ent_Lnt,Ent_Isparagon,District_Id,FDAID,Kitchen_View,EnterType,LicenceType,LicenceNum,LicenceStartDate,LicenceEndDate,LastQuantizationLevel,TheQuantizationLevel,ApprovalProject,RegisteredOwner from Bas_Enter_User ");
            strSql.Append(" where ID=model.ID");
            SME.Food.Surperise.Model.Bas_Enter_User_Model model = new SME.Food.Surperise.Model.Bas_Enter_User_Model();
            DataSet ds = DbHelper.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SME.Food.Surperise.Model.Bas_Enter_User_Model DataRowToModel(DataRow row)
        {
            SME.Food.Surperise.Model.Bas_Enter_User_Model model = new SME.Food.Surperise.Model.Bas_Enter_User_Model();
            if (row != null)
            {
                if (row["ID"] != null && row["ID"].ToString() != "")
                {
                    model.ID = int.Parse(row["ID"].ToString());
                }
                if (row["Login_Name"] != null)
                {
                    model.Login_Name = row["Login_Name"].ToString();
                }
                if (row["Password"] != null)
                {
                    model.Password = row["Password"].ToString();
                }
                if (row["Enter_No"] != null)
                {
                    model.Enter_No = row["Enter_No"].ToString();
                }
                if (row["Enter_Name"] != null)
                {
                    model.Enter_Name = row["Enter_Name"].ToString();
                }
                if (row["Enter_ShortName"] != null)
                {
                    model.Enter_ShortName = row["Enter_ShortName"].ToString();
                }
                if (row["Link_Man"] != null)
                {
                    model.Link_Man = row["Link_Man"].ToString();
                }
                if (row["Sex"] != null && row["Sex"].ToString() != "")
                {
                    model.Sex = int.Parse(row["Sex"].ToString());
                }
                if (row["Link_Phone"] != null)
                {
                    model.Link_Phone = row["Link_Phone"].ToString();
                }
                if (row["Email"] != null)
                {
                    model.Email = row["Email"].ToString();
                }
                if (row["qqNum"] != null)
                {
                    model.qqNum = row["qqNum"].ToString();
                }
                if (row["Ent_Address"] != null)
                {
                    model.Ent_Address = row["Ent_Address"].ToString();
                }
                if (row["Ent_Logo"] != null && row["Ent_Logo"].ToString() != "")
                {
                    model.Ent_Logo = (byte[])row["Ent_Logo"];
                }
                if (row["Ent_ShowPic"] != null)
                {
                    model.Ent_ShowPic = row["Ent_ShowPic"].ToString();
                }
                if (row["Ent_Commitment"] != null)
                {
                    model.Ent_Commitment = row["Ent_Commitment"].ToString();
                }
                if (row["Ent_Introduce"] != null)
                {
                    model.Ent_Introduce = row["Ent_Introduce"].ToString();
                }
                if (row["Ent_Lat"] != null)
                {
                    model.Ent_Lat = row["Ent_Lat"].ToString();
                }
                if (row["Ent_Lnt"] != null)
                {
                    model.Ent_Lnt = row["Ent_Lnt"].ToString();
                }
                if (row["Ent_Isparagon"] != null && row["Ent_Isparagon"].ToString() != "")
                {
                    model.Ent_Isparagon = int.Parse(row["Ent_Isparagon"].ToString());
                }
                if (row["District_Id"] != null && row["District_Id"].ToString() != "")
                {
                    model.District_Id = int.Parse(row["District_Id"].ToString());
                }
                if (row["FDAID"] != null && row["FDAID"].ToString() != "")
                {
                    model.FDAID = int.Parse(row["FDAID"].ToString());
                }
                if (row["Kitchen_View"] != null && row["Kitchen_View"].ToString() != "")
                {
                    model.Kitchen_View = int.Parse(row["Kitchen_View"].ToString());
                }
                if (row["EnterType"] != null && row["EnterType"].ToString() != "")
                {
                    model.EnterType = int.Parse(row["EnterType"].ToString());
                }
                if (row["LicenceType"] != null && row["LicenceType"].ToString() != "")
                {
                    model.LicenceType = int.Parse(row["LicenceType"].ToString());
                }
                if (row["LicenceNum"] != null)
                {
                    model.LicenceNum = row["LicenceNum"].ToString();
                }
                if (row["LicenceStartDate"] != null)
                {
                    model.LicenceStartDate = row["LicenceStartDate"].ToString();
                }
                if (row["LicenceEndDate"] != null)
                {
                    model.LicenceEndDate = row["LicenceEndDate"].ToString();
                }
                if (row["LastQuantizationLevel"] != null)
                {
                    model.LastQuantizationLevel = row["LastQuantizationLevel"].ToString();
                }
                if (row["TheQuantizationLevel"] != null)
                {
                    model.TheQuantizationLevel = row["TheQuantizationLevel"].ToString();
                }
                if (row["ApprovalProject"] != null)
                {
                    model.ApprovalProject = row["ApprovalProject"].ToString();
                }
                if (row["RegisteredOwner"] != null)
                {
                    model.RegisteredOwner = row["RegisteredOwner"].ToString();
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,Login_Name,Password,Enter_No,Enter_Name,Enter_ShortName,Link_Man,Sex,Link_Phone,Email,qqNum,Ent_Address,Ent_Logo,Ent_ShowPic,Ent_Commitment,Ent_Introduce,Ent_Lat,Ent_Lnt,Ent_Isparagon,District_Id,FDAID,Kitchen_View,EnterType,LicenceType,LicenceNum,LicenceStartDate,LicenceEndDate,LastQuantizationLevel,TheQuantizationLevel,ApprovalProject,RegisteredOwner ");
            strSql.Append(" FROM Bas_Enter_User ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" ID,Login_Name,Password,Enter_No,Enter_Name,Enter_ShortName,Link_Man,Sex,Link_Phone,Email,qqNum,Ent_Address,Ent_Logo,Ent_ShowPic,Ent_Commitment,Ent_Introduce,Ent_Lat,Ent_Lnt,Ent_Isparagon,District_Id,FDAID,Kitchen_View,EnterType,LicenceType,LicenceNum,LicenceStartDate,LicenceEndDate,LastQuantizationLevel,TheQuantizationLevel,ApprovalProject,RegisteredOwner ");
            strSql.Append(" FROM Bas_Enter_User ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Bas_Enter_User ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelper.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.ID desc");
            }
            strSql.Append(")AS Row, T.*  from Bas_Enter_User T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("model.tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("model.fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("model.PageSize", SqlDbType.Int),
                    new SqlParameter("model.PageIndex", SqlDbType.Int),
                    new SqlParameter("model.IsReCount", SqlDbType.Bit),
                    new SqlParameter("model.OrderType", SqlDbType.Bit),
                    new SqlParameter("model.strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Bas_Enter_User";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

